<template>
	<view class="drafts">
		<view class="card" v-for="(item,index) in data" @click="changeUrl(item)">
			<view class="top_card">
				<view class="times">
					{{item.createTime}}
				</view>
				<view class="icons">
					<uni-icons custom-prefix="trash" type="trash" size="30" @click="Delete(item.id,index)"></uni-icons>
				</view>
			</view>
			<view class="bottom_card">
				<image :src="getImgUrl(item.postPicture[0].pricturePath)" mode="" class="imgs"></image>
				<view class="fonts">
					{{item.postContent}}
				</view>
			</view>
		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog :type="msgType" cancelText="取消" confirmText="同意" title="提示" content="'确定要删除吗？"
				@confirm="dialogConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import {
		drafts,
		Informationdel
	} from '@/utils/OnetoOneaApi.js';
	import {
		imgBaseUrl,baseURL
	} from '@/utils/baseUrl.js'
	export default {
		data() {
			return {
				imgs: 'https://img2.baidu.com/it/u=1793887084,2705047649&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1698339600&t=0683446dfe81816b66fa7375b5fdeed4',
				data: [],
				pageNo: 1,
				id: '',
				idx: ''

			}
		},
		onReachBottom() {
			this.pageNo + 1;
			console.log(this.pageNo++, ' this.pageNo++;');
			this.dataList();
		},
		onShow() {
			this.data = []
			this.dataList()
		},
		methods: {
			// 草稿列表数据渲染
			async dataList() {
				const userInfo = uni.getStorageSync('userInfo')
				console.log(userInfo, 'user');
				const id = userInfo.id
				const status = 1
				const pageNo = this.pageNo
				const res = await drafts(id, status, pageNo)
				this.data = [...this.data, ...res.result.records]
			},

			changeUrl(item){
				uni.navigateTo({
					url:`../../../subPackagesA/pages/addForum/addForum?info=${JSON.stringify(item)}`,
				})
			},

			// 图片渲染
			getImgUrl(image) {
				console.log(baseURL + '/' + image,'////////////////');
				return baseURL + '/' + image;
			},
			async Delete(id, index) {
				console.log(id, index, 'index');
				this.$refs.alertDialog.open()
				this.id = id
				this.idx = index


			},
		async	dialogConfirm() {
				const res = await Informationdel(this.id)
				if (res.code == 200) {
					this.data.splice(this.idx, 1)
					uni.showToast({
						title: '删除成功',
						//将值设置为 success 或者直接不用写icon这个参数
						icon: 'success',
						//显示持续时间为 2秒
						duration: 2000
					})
				} else {
					uni.showToast({
						title: '删除失败',
						//将值设置为 success 或者直接不用写icon这个参数
						icon: 'success',
						//显示持续时间为 2秒
						duration: 2000
					})
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.drafts {
		width: 100%;
		// height: 100vh;
		background: #F5F5F5;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;

		.card {
			width: 87%;
			height: 230rpx;
			margin-top: 20rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			opacity: 1;
			padding: 39rpx 30rpx 30rpx 31rpx;

			.top_card {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding-bottom: 23rpx;

				.times {
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #141419;
				}
			}

			.bottom_card {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.imgs {
					width: 140rpx;
					height: 140rpx;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					opacity: 1;
				}

				.fonts {
					width: 477rpx;
					font-size: 32rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #222229;
				}
			}
		}
	}
</style>

<style>
	page{
		background:#F5F5F5;
	}
</style>